package com.ruoyi.printers.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.printers.domain.Printers;
import com.ruoyi.printers.service.IPrintersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 打印机管理Controller
 * 
 * @author ruoyi
 * @date 2025-02-28
 */
@RestController
@RequestMapping("/printerManagement/printers")
public class PrintersController extends BaseController
{
    @Autowired
    private IPrintersService printersService;

    /**
     * 查询打印机管理列表
     */
    @PreAuthorize("@ss.hasPermi('printerManagement:printers:list')")
    @GetMapping("/list")
    public TableDataInfo list(Printers printers)
    {
        startPage();
        List<Printers> list = printersService.selectPrintersList(printers);
        return getDataTable(list);
    }

    /**
     * 导出打印机管理列表
     */
    @PreAuthorize("@ss.hasPermi('printerManagement:printers:export')")
    @Log(title = "打印机管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Printers printers)
    {
        List<Printers> list = printersService.selectPrintersList(printers);
        ExcelUtil<Printers> util = new ExcelUtil<Printers>(Printers.class);
        util.exportExcel(response, list, "打印机管理数据");
    }

    /**
     * 获取打印机管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('printerManagement:printers:query')")
    @GetMapping(value = "/{serialNumber}")
    public AjaxResult getInfo(@PathVariable("serialNumber") String serialNumber)
    {
        return success(printersService.selectPrintersBySerialNumber(serialNumber));
    }

    /**
     * 新增打印机管理
     */
    @PreAuthorize("@ss.hasPermi('printerManagement:printers:add')")
    @Log(title = "打印机管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Printers printers)
    {
        return toAjax(printersService.insertPrinters(printers));
    }

    /**
     * 修改打印机管理
     */
    @PreAuthorize("@ss.hasPermi('printerManagement:printers:edit')")
    @Log(title = "打印机管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Printers printers)
    {
        return toAjax(printersService.updatePrinters(printers));
    }

    /**
     * 删除打印机管理
     */
    @PreAuthorize("@ss.hasPermi('printerManagement:printers:remove')")
    @Log(title = "打印机管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{serialNumbers}")
    public AjaxResult remove(@PathVariable String[] serialNumbers)
    {
        return toAjax(printersService.deletePrintersBySerialNumbers(serialNumbers));
    }
}
